#--*- encoding: shift-jis -*--

from __future__ import with_statement

import yaml, _yaml
import sys
import time

def yaml_bench(filename):
    with open(filename, "r") as f:
        return len(list(yaml.load_all(f, Loader = yaml.CLoader)))

filename, n = sys.argv[1], int(sys.argv[2])
count = 0

s = time.time()
for i in range(n):
    count += yaml_bench(filename)
e = time.time()


import platform
from subprocess import *

print yaml.dump({
    "python/cyaml": {
        "benchmark_script": __file__,
        "language": "python",
        "interpreter": {
            "name": "python",
            "version": platform.python_version(),
            "banner": Popen("python --version", stderr=PIPE).communicate()[1].strip(),
        },
        "library": {
            "name": "PyYAML",
            "version": "3.04",
            "language": ["C"],
            "native_library": {
                "name": "libyaml",
                "version": _yaml.get_version_string(),
            }
        },
        "result": {
            filename: {
                "loaded": count,
                "wallclock": e - s,
            }
        }
    }
})
